import axios from '@/utils/request'
export default {
  SecondCategory: {
    entity: { name: 'Category', prefix: `manage` },
    form: {
      fields: [
        'name',
        {
          property: 'parent',
          relation_filter: {
            '@filter': `!entity.getParent() && entity.getType().getSlug() != 'content'`
          },
          field_options: {
            label: '可销售门店类型'
          }
        },
        { property: 'enabled', required: false, default_value: true },
        { property: 'sequence', required: false, default_value: 255 }
        // { property: 'icon', required: false, type: 'image' }
      ]
    },
    list: {
      query: {
        '@filter': `entity.getParent() && !entity.getParent().getParent()`
      },
      list_display: [
        'id',
        'name',
        {
          property: 'parent',
          label: '可销售门店类型'
        },
        'enabled',
        'sequence'
      ],
      list_filter: {
        // 'type.id': () => {
        //   return axios
        //     .get('/manage/types')
        //     .then(res =>
        //       Object.assign({ __label: '类型' },
        //         ...res.data.map(v => { return { [v.id]: v.name } })
        //       )
        //     )
        // },
        'parent.id': () => {
          return axios
            .get('/manage/categories', {
              params: {
                '@filter': `!entity.getParent()`
              }
            })
            .then(res =>
              Object.assign({ __label: '销售分类' },
                ...res.data.map(v => { return { [v.id]: v.name } })
              )
            )
        }
      }
    }
  }
}